//
//  ACMemoryCacheViewController.m
//  ACCache_Example
//
//  Created by autohome on 2021/8/19.
//  Copyright © 2021 autohome. All rights reserved.
//

#import "ACMemoryCacheViewController.h"
#import "ACMemoryCache.h"

@interface ACMemoryCacheViewController ()

@property (strong, nonatomic) ACMemoryCache *cache;

@end

@implementation ACMemoryCacheViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self beginCache];
}

- (void)beginCache {
    for (int i = 0; i<100; i++) {
        NSString *obj = [NSString stringWithFormat:@"object--%d",i];
        [self.cache setObject:obj forKey:@(i)];
    }
    
    
}

- (ACMemoryCache *)cache {
    if (!_cache) {
        _cache = [[ACMemoryCache alloc] initWithName:@"MS"];
        _cache.didEnterBackgroundBlock = ^(ACMemoryCache * _Nonnull cache) {
            for (int i = 0; i < 10; i ++) {
                NSString *s =   [cache objectForKey:@(i)];
                NSLog(@"%@ didEnterBackgroundBlock ",s);
            }
        };
    }
    return _cache;
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    for (int i = 0; i < 100; i ++) {
        NSString *s =   [self.cache objectForKey:@(i)];
        NSLog(@"%@ objectForKey ",s);
    }
}

- (void)dealloc {
    NSLog(@"%s",__func__);
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
